@extends('admin.layouts.master')
@section('content')
    <link rel="stylesheet"
          href="{{asset('static/bootstrap/css/bootstrap.min.css')}}">
    <table class="mdui-table mdui-table-hoverable mdui-typo">
        <caption class="mdui-typo-title">用户详情</caption>
        <thead>
        <tr>
            <th>用户ID</th>
            <th>昵称</th>
            <th>手机号</th>
            <th>邮箱</th>
            <th>注册时间</th>
            <th>登录权限</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            @foreach($users as $user)
                <td>{{$user->id}}</td>
                <td>{{$user->nickname}}</td>
                <td>{{$user->phone}}</td>
                <td>{{$user->email}}</td>
                <td>{{$user->created_at}}</td>
                <td>
                    <label class="mdui-switch">
                        <input type="checkbox" is_allowed="{{$user->is_allowed}}"
                               class="change" {{$user->is_allowed==1?'checked':''}}/>
                        <i class="mdui-switch-icon"></i>
                    </label>
                </td>
            @endforeach
        </tr>
        </tbody>
    </table>
    <table class="mdui-table mdui-table-hoverable mdui-typo mdui-m-t-1">
        <caption class="mdui-typo-title">用户微博</caption>
        <thead>

        <tr>
            <th>#</th>
            <th>微博摘要</th>
            <th>话题</th>
            <th>发表时间</th>
        </tr>
        </thead>
        <tbody>
        @foreach($details as $detail)
        <tr>
            <td>{{$detail->id}}</td>
            <td>{{$detail->content}}</td>
            <td>#{{$detail->topic}}#</td>
            <td>{{$detail->created_at}}</td>
        </tr>
        @endforeach
        </tbody>
    </table>
    <!-- jQuery 文件 -->
    <script src="{{asset('static/jquery/jquery.min.js')}}"></script>
    <!-- Bootstrap JavaScript 文件 -->
    <script src="{{asset('static/bootstrap/js/bootstrap.min.js')}}"></script>
@endsection
@section('js')
        <script>
        $(".change").click(function () {
            //获取每次选择得到的id
            var user_id = $(this).parent().parent().parent().find('td').first().text();

            //增加一个标识
            var is_allowed = $(this).attr('is_allowed');
            //指定选定的ID
            var mythis = $(this);
            $.ajax({
                url: '/admin/user/'+ user_id +'/update',
                dataType: 'json',
                type:'get',
                data: {'is_allowed': is_allowed},
                success: function (data) {
                    if (data.message === 1) {
                        mythis.attr('checked', '');
                        mythis.attr('is_allowed', '1');
                    } else {
                        mythis.removeAttr('checked');
                        mythis.attr('is_allowed', '0');
                    }
                }
            });
        });

    </script>
    <script>
        $(".change_show").click(function () {
            //获取每次选择得到的id
            var detail_id = $(this).parent().parent().parent().find('td').first().text();

            //增加一个标识
            var is_show = $(this).attr('is_show');
            //指定选定的ID
            var mythis = $(this);
            $.ajax({
                url: '/admin/user/'+ detail_id +'/status',
                dataType: 'json',
                type:'get',
                data: {'is_show': is_show},
                success: function (data) {
                    if (data.message === 1) {
                        mythis.attr('checked', '');
                        mythis.attr('is_show', '1');
                    } else {
                        mythis.removeAttr('checked');
                        mythis.attr('is_show', '0');
                    }
                }
            });
        });
    </script>
@endsection